<?php
include('include/config.inc.php');
if(!isset($_SESSION['s_activId'.$cfgPack])
  || (isset($_SESSION['s_userType'.$cfgPack]) && isset($cfgFileNames['completeReport'][$_SESSION['s_userType'.$cfgPack]]) 
      && $cfgFileNames['completeReport'][$_SESSION['s_userType'.$cfgPack]] == 0))
{
  $_SESSION['s_urlRedirectDir'] = $_SERVER['REQUEST_URI'];
  header("Location:checkLogin.php");
}
else
{
	/////////////////  Bill date View:Start
	if(isset($_REQUEST['fromDateYear']))
		$fromDate  = $_REQUEST['fromDateYear']."-".$_REQUEST['fromDateMonth']."-".$_REQUEST['fromDateDay'];
	else
		$fromDate  = date("Y-m-01");
	
	if(isset($_REQUEST['toDateYear']))
		$toDate    = $_REQUEST['toDateYear']."-".$_REQUEST['toDateMonth']."-".$_REQUEST['toDateDay'];
	else
		$toDate    = date("Y-m-d");
	/////////////////  Bill date View:Stop
	
  $complainCallDetailArray  = array();
  $newInstallDetailArray  = array();
  $newInstallCount        = 0;
  $complainCount          = 0;
  $msg                    = "";
  $otherServiceArray      = array();
  $otherCount             = 0;


  $selectComplainEntry = "SELECT complainservice.complainServiceId,DATE_FORMAT(complainservice.complainDate,'%d-%m-%Y') AS complainDate,
                                 DATE_FORMAT(complainservice.targetedDate,'%d-%m-%Y') AS targetedDate,complainservice.description,complainservice.importantPoint,
                                 complainservice.serviceCharge,complainservice.remarks,complainservice.amountCollected,party.partyId,party.companyName,
                                 typeofcall.type,category.categoryId,category.categoryName,typeofcall.typeOfCallId
				  						      FROM complainservice
					 						      LEFT JOIN party      ON party.partyId           = complainservice.partyId
											      LEFT JOIN category   ON category.categoryId     = complainservice.categoryId
											      LEFT JOIN typeofcall ON typeofcall.typeOfCallId = complainservice.typeOfCallId
											     WHERE complainservice.status = 'D'
	                           AND complainservice.complainDate <= '".$toDate."'
	                           AND complainservice.complainDate >= '".$fromDate."'
  											   ORDER BY party.companyName";
  $selectComplainEntryResult = mysql_query($selectComplainEntry);
  $complaneEntryRow = mysql_num_rows($selectComplainEntryResult);
  ///////////////select query for complainservice table/////////////////
  if($complaneEntryRow > 0)
  {
	  while($complaneEntryRow = mysql_fetch_array($selectComplainEntryResult))
	  {
		  $complainCallDetailArray[$complainCount]['complainServiceId']  = $complaneEntryRow['complainServiceId'];
	    $complainCallDetailArray[$complainCount]['companyName']        = $complaneEntryRow['companyName'];
		  $complainCallDetailArray[$complainCount]['categoryName']       = wordwrap($complaneEntryRow['categoryName'],15,"<br />\n",TRUE);
		  $complainCallDetailArray[$complainCount]['complainDate']       = $complaneEntryRow['complainDate'];
		  $complainCallDetailArray[$complainCount]['targetedDate']       = $complaneEntryRow['targetedDate'];
		  $complainCallDetailArray[$complainCount]['description']        = $complaneEntryRow['description'];
		  $complainCallDetailArray[$complainCount]['importantPoint']     = $complaneEntryRow['importantPoint'];
		  $complainCallDetailArray[$complainCount]['type']               = $complaneEntryRow['type'];
		  $complainCallDetailArray[$complainCount]['serviceCharge']      = $complaneEntryRow['serviceCharge'];
		  $complainCallDetailArray[$complainCount]['remarks']            = $complaneEntryRow['remarks'];
		  $complainCallDetailArray[$complainCount]['amountCollected']    = $complaneEntryRow['amountCollected'];
		  $complainCount++;
	 }   
 }
 else
 {
   $msg = '<tr><td align="center" colspan="10"> <h2><font color="red"><b>Record Not Found...!</b></h2></font></td></tr>';
 }
 
 ///////////////select query for complainservice table over/////////////////
 ///////////////select query for newinstallationmaster AND newinstallationdetail table/////////////////
  $selectNewInstall = "SELECT newinstallationmaster.newinstallationMasterId,newinstallationmaster.installationDate,
                              DATE_FORMAT(newinstallationmaster.installationDate,'%d-%m-%Y') AS installationDate,
                              newinstallationmaster.status,party.companyName,category.categoryName,
                              newinstallationdetail.description
				  						   FROM newinstallationmaster
					 						   LEFT JOIN newinstallationdetail ON newinstallationmaster.newinstallationMasterId = newinstallationdetail.newinstallationMasterId 
					 						   LEFT JOIN party                 ON party.partyId = newinstallationmaster.partyId
											   LEFT JOIN category              ON category.categoryId       = newinstallationdetail.categoryId
											  WHERE newinstallationmaster.status = 'D'
	                        AND newinstallationmaster.installationDate <= '".$toDate."'
	                        AND newinstallationmaster.installationDate >= '".$fromDate."'											    
										 ORDER BY newinstallationmaster.newinstallationMasterId DESC";
  $selectNewInstallResult = mysql_query($selectNewInstall);
  $newInstallRow = mysql_num_rows($selectNewInstallResult);
  if($newInstallRow > 0)
  {
	  while($newInstallRow = mysql_fetch_array($selectNewInstallResult))
	  {
		  $newInstallDetailArray[$newInstallCount]['newinstallationMasterId'] = $newInstallRow['newinstallationMasterId'];
	    $newInstallDetailArray[$newInstallCount]['companyName']             = $newInstallRow['companyName'];
		  $newInstallDetailArray[$newInstallCount]['categoryName']            = $newInstallRow['categoryName'];
		  $newInstallDetailArray[$newInstallCount]['installationDate']        = $newInstallRow['installationDate'];
		  $newInstallDetailArray[$newInstallCount]['description']             = $newInstallRow['description'];
		  $newInstallCount++;
	  } 
	}  
 else
 {
	$msg = '<tr><td align="center" colspan="10"> <h2><font color="red"><b>Record Not Found...!</b></h2></font></td></tr>';
 }
 ///////////////select query for newinstallationmaster AND newinstallationdetail table over/////////////////
 ///////////////select query for OtherService table/////////////////
 $selectOtherService = "SELECT otherservice.partyId,otherservice.serviceType,
                               DATE_FORMAT(otherservice.complainDate,'%d-%m-%Y') AS complainDate,
                               DATE_FORMAT(otherservice.targetedDate,'%d-%m-%Y') AS targetedDate,
                               otherservice.categoryId,otherservice.description,otherservice.importantPoint,otherservice.status,
                               party.companyName,party.partyId,category.categoryId,category.categoryName
				  						    FROM otherservice
					 						    LEFT JOIN party    ON party.partyId       = otherservice.partyId
											    LEFT JOIN category ON category.categoryId = otherservice.categoryId
											   WHERE otherservice.status = 'D'
	                         AND otherservice.complainDate <= '".$toDate."'
	                         AND otherservice.complainDate >= '".$fromDate."'											   
											ORDER BY party.companyName";
  $selectOtherServiceResult = mysql_query($selectOtherService);
  $OtherServiceResultRow = mysql_num_rows($selectOtherServiceResult);
  if($OtherServiceResultRow > 0)
  {
	  while($OtherServiceResultRow = mysql_fetch_array($selectOtherServiceResult))
	  {
	    $otherServiceArray[$otherCount]['companyName']       = $OtherServiceResultRow['companyName'];
		  $otherServiceArray[$otherCount]['serviceType']       = $OtherServiceResultRow['serviceType'];
		  $otherServiceArray[$otherCount]['categoryName']      = $OtherServiceResultRow['categoryName'];
		  $otherServiceArray[$otherCount]['complainDate']      = $OtherServiceResultRow['complainDate'];
		  $otherServiceArray[$otherCount]['targetedDate']      = $OtherServiceResultRow['targetedDate'];
		  $otherServiceArray[$otherCount]['description']       = $OtherServiceResultRow['description'];
		  $otherServiceArray[$otherCount]['importantPoint']    = $OtherServiceResultRow['importantPoint'];
		  $otherCount++;
	 }   
  }
  else
  {
	  $msg = '<tr><td align="center" colspan="10"> <h2><font color="red"><b>Record Not Found...!</b></h2></font></td></tr>';
  }
 ///////////////select query for OtherService table Over/////////////////
  include("./bottom.php");
  $smarty->assign("msg",$msg);
  $smarty->assign("complainCallDetailArray",$complainCallDetailArray);
  $smarty->assign("newInstallDetailArray",$newInstallDetailArray);
  $smarty->assign("otherServiceArray",$otherServiceArray);
	$smarty->assign("fromDate",$fromDate);
	$smarty->assign("toDate",$toDate);  
	$smarty->display("completeReport.tpl");
}
?>